package logic

import (
	"context"

	"message/internal/svc"
	"message/pb/message"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetMessageCountLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetMessageCountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMessageCountLogic {
	return &GetMessageCountLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// GetMessageCount 获取消息计数
func (l *GetMessageCountLogic) GetMessageCount(in *message.MessageCountRequest) (*message.MessageCountResponse, error) {
	total, singleMap, groupMap, err := l.svcCtx.MessageAggregationModel.GetMessageCount(l.ctx, in.UserId, in.SenderId, in.ReceiverType, in.ReceiverId, in.Status)
	if err != nil {
		return nil, err
	}
	return &message.MessageCountResponse{Total: total, SingleMap: singleMap, GroupMap: groupMap}, nil
}
